package com.ykg.service.impl;

import com.ykg.dto.UnloadShipDTO;
import com.ykg.mapper.EntrustMapper;
import com.ykg.mapper.ListMapper;
import com.ykg.pojo.Entrust;
import com.ykg.service.IDTOService;
import com.ykg.service.IUnloadShipService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * 类(接口)：
 * Created on 2021/6/25 15:56.
 * Author: zetong
 * Description:
 */
@Service
public class UnloadShipServiceImpl implements IUnloadShipService {

    @Autowired
    private EntrustMapper entrustMapper;
    @Autowired
    private IDTOService idtoService;
    @Autowired
    private ListMapper listMapper;


    @Override//获得卸货列表
    public List<Entrust> getEntrustUnload(){
        List<Entrust> entrusts = new ArrayList<Entrust>();
        entrusts.addAll(entrustMapper.getEntrustByState(7));
        entrusts.addAll(entrustMapper.getEntrustByState(8));
        return entrusts;
    }
    @Override//查看卸货详细信息
    public UnloadShipDTO getEntrustUnloadDetailed(String entrustId){
        Entrust entrust = entrustMapper.findByEntrustId(entrustId);
        listMapper.updateListState(entrust.getListId(),3);
        UnloadShipDTO unloadShipDTO = idtoService.createUnloadShipDTO(entrust);
        return unloadShipDTO;
    }
    @Override//完成卸货
    public int finishUnload(String entrustId){
        Entrust entrust = entrustMapper.findByEntrustId(entrustId);
        listMapper.updateListState(entrust.getListId(),4);
        int result = entrustMapper.updateState(entrustId,8);
        return result;
    }
}
